package com.xhu.collegestudentrentalsystem.config;

import com.xhu.collegestudentrentalsystem.interceptor.IndexInterceptor;
import com.xhu.collegestudentrentalsystem.interceptor.LoginInterceptor;
import com.xhu.collegestudentrentalsystem.interceptor.LoginRequireInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author zhu huilin
 * @date 2023/2/23 20:31
 *
 *  处理静态资源拦截问题
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {


    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private LoginRequireInterceptor loginRequireInterceptor;

    @Autowired
    private IndexInterceptor indexInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //除了静态资源外，需要拦截所有的请求
        registry.addInterceptor(loginInterceptor)
                .excludePathPatterns("/**/*.css","/**/*.js","/**/*.png","/**/*.jpg","/**/*.jpeg");

        registry.addInterceptor(loginRequireInterceptor)
                .excludePathPatterns("/**/*.css","/**/*.js","/**/*.png","/**/*.jpg","/**/*.jpeg");

        registry.addInterceptor(indexInterceptor)
                .addPathPatterns("/index");
    }

    /*@Override
    public void addCorsMappings(CorsRegistry registry) {
        // 允许前端的跨域访问
        registry.addMapping("/**").allowedOrigins("*");
    }*/
}
